import React, { useEffect, useState, useContext } from 'react'
import { Context } from '../../contextStore'
const ContextHookDemo = (props) => {
    const [contextState, contextDispatch] = useContext(Context)
    const setStore = (path, value) => contextDispatch({ type: 'setStore', data: { path, value } })
    const {user} = contextState
    return (
        <div>
            <p>姓名: {user.name}</p>
            <p>邮箱: {user.email}</p>
            <button onClick={() => {
                if (user.name === 'takzhang') {
                    setStore('user.name', '潭底剑仙')
                } else {
                    setStore('user.name', 'takzhang')
                }
            }}>修改ContextStore的user.name</button>
        </div>
    )
}
export default ContextHookDemo